﻿using System;

using System.Linq;
using DataAccess.Entities;
using DataAccess.Repositories;
using Zeenck.Models;

namespace Zeenck.DataAccess
{
    public static class ProfileModule
    {
        public static Profile GetProfile(int profileId)
        {
            Profile profile = null;

            try
            {
                IRepository<Profile> repo = new ProfileRepository();
                profile = repo.GetById(profileId);
            }
            catch (Exception)
            {
                
            }

            return profile;
        }

        public static void UpdateProfile(ZeenckProfile profile)
        {
            try
            {
                IRepository<Gender> genderRepo = new GenderRepository();
                Gender gender = genderRepo.Find(profile.Personal.Gender, 1).ToList().First();
                Gender interestedIn = genderRepo.Find(profile.Personal.InterestedIn, 1).ToList().First();

                IRepository<RelationshipStatus> relationRepo = new RelationshipStatusRepository();
                RelationshipStatus relationStatus =
                    relationRepo.Find(profile.Personal.RelationshipStatus, 1).ToList().First();

                IRepository<Interest> interestRepo = new InterestRepository();
                Interest passion = interestRepo.Find(profile.Basic.Passion, 1).ToList().First();

                IRepository<Profile> repo = new ProfileRepository();
                Profile p = repo.GetById(profile.Id);
                p.Bio = profile.Portfolio.Bio;
                p.Birthday = profile.Personal.Birthday;
                p.Gender = gender;
                p.Complete = true;
                p.InterestedIn = interestedIn;
                p.Passion = passion;
                p.Picture = profile.Basic.Picture;
                p.RelationshipStatus = relationStatus;
                p.Status = profile.Basic.Status;
                p.Url = profile.Portfolio.Url;

                repo.Update(p);
            } catch (Exception)
            {
                
            }
        }
    }
}